package nia.chapter4.mytest;

import io.netty.channel.*;

import java.util.Date;

/**
 * @Author: jia
 * @Descirption:
 * @Date: 2018/5/11 15:10
 * @Modified By:
 */


public class TestHandler extends SimpleChannelInboundHandler {
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, Object o) throws Exception {
        //获取管道
        ChannelPipeline pipeline = ctx.channel().pipeline();
        pipeline.addLast();
        ChannelFuture future = ctx.writeAndFlush(new Date());
        //添加监听器，在操作完成后，并且没有错误时执行
        future.addListener(new ChannelFutureListener() {
            @Override
            public void operationComplete(ChannelFuture channelFuture) throws Exception {
                System.out.println("写输入完成！");
            }
        });
    }
}
